/**
 * 
 */
package com.gragra.sampling.sequentialStructure;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @author Christoph Teichmann
 * 01.06.2013
 */
public enum NumericalType implements ExtensionInformationValue
{
	/**
	 * 
	 */
	LeadingNumbers,
	/**
	 * 
	 */
	TrailingNumbers,
	/**
	 * 
	 */
	AllNumbers,
	/**
	 * 
	 */
	InternalNumbers,
	/**
	 * 
	 */
	NoNumbers;
	@Override
	public ExtensionInformationLevel getLevel()
	{return ExtensionLevels.NumericalLevel;}
	/**
	 * 
	 */
	private int number = -1;
	/* (non-Javadoc)
	 * @see com.gragra.sampling.sequentialStructure.ExtensionInformationValue#getNumber()
	 */
	@Override
	public int getNumber()
	{
		if(number < 0)
		{
			for(int i=0;i<NumericalType.values().length;++i)
			{
				if(NumericalType.values()[i] == this)
				{return (number = i);}
			}
		}
		return number;
	}
	/**
	 * 
	 */
	private static final Pattern pat = Pattern.compile("\\p{Digit}+");
	/**
	 * 
	 * @return
	 */
	public static NumericalType classify(String input)
	{
		Matcher mat = pat.matcher(input);
		if(mat.matches())
		{return AllNumbers;}
		mat.reset();
		if(mat.find())
		{
			if(mat.start() == 0)
			{return LeadingNumbers;}
			if(mat.end() == input.length())
			{return TrailingNumbers;}
			return InternalNumbers;
		}
		else
		{return NoNumbers;}
	}
}